<extend name="Public/Dialog/Common"/>
<block name="pageContent">
    <div class="bjui-pageContent">
        <form action="{:U('update')}" class="pageForm" data-toggle="validate" method="post">
            <!-- 菜单id号 -->
            <input type="hidden" name="id" value="{$data.id|default=I('id')}"/>
            <input type="hidden" name="pid" value="{$data.pid|default=''}"/>
            <input type="hidden" name="model_id" value="{$data.model_id|default=I('model_id')}"/>
            <input type="hidden" name="group_id" value="{$data.group_id|default=''}"/>
            <input type="hidden" name="category_id" value="{$data.category_id|default=''}">
                <ul class="nav nav-tabs" role="tablist">
                    <volist name=":parse_config_attr($model['field_group'])" id="group">
                        <li <eq name="key" value="1">class="active"</eq>>
                        <a href="#Article{$data.id}tab{$key}" role="tab" data-toggle="tab">{$group}</a>
                        </li>
                    </volist>
                </ul>
                <div class="tab-content">
                    <volist name=":parse_config_attr($model['field_group'])" id="group">
                        <div id="Article{$data.id}tab{$key}" class="tab-pane fade <eq name="key" value="1">active in</eq>">
                        <fieldset>
                        <volist name="fields[$key]" id="field">
                            <div class="col-md-12">
                            <if condition="$field['is_show'] == 1 || $field['is_show'] == 3">
                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        {$field['title']}
                                    <span class="check-tips">
                                        <notempty name="field['remark']">（{$field['remark']}）</notempty>
                                    </span>
                                    </div>
                                    <div class="panel-body">
                                        <switch name="field.type">
                                            <case value="num">
                                                <input type="text" class="text input-mid" name="{$field.name}" value="{$data[$field['name']]}"></case>
                                            <case value="string">
                                                <input type="text" class="text input-large" name="{$field.name}" value="{$data[$field['name']]}"></case>
                                            <case value="textarea">
                                                <label class="textarea input-large">
                                                    <textarea name="{$field.name}">{$data[$field['name']]}</textarea>
                                                </label>
                                            </case>
                                            <case value="date">
                                                <?php if($field['name']=='create_time'):?>
                                                <input type="text" name="{$field.name}" value="<?php echo $data[$field['name']] ? date('Y-m-d', $data[$field['name']]) : date('Y-m-d', time());?>" data-toggle="datepicker" data-rule="date" placeholder="请选择日期" />
                                                <?php else:?>
                                                <input type="text" name="{$field.name}" value="{$data[$field['name']]|date='Y-m-d',###}" data-toggle="datepicker" data-rule="date" placeholder="请选择日期" />
                                                <?php endif;?>
                                            </case>
                                            <case value="datetime">
                                                <?php if($field['name']=='create_time'):?>
                                                <input type="text" name="{$field.name}" value="<?php echo $data[$field['name']] ? date('Y-m-d H:i:s', $data[$field['name']]) : date('Y-m-d H:i:s', time());?>" data-toggle="datepicker" data-rule="datetime" placeholder="请选择日期" />
                                                <?php else:?>
                                                <input type="text" name="{$field.name}" value="{$data[$field['name']]|date='Y-m-d H:i:s',###}" data-toggle="datepicker" data-rule="datetime" placeholder="请选择日期" />
                                                <?php endif;?>
                                            </case>
                                            <case value="bool">
                                                <select name="{$field.name}">
                                                    <volist name=":parse_field_attr($field['extra'])" id="vo">
                                                        <option value="{$key}" <eq name="data[$field['name']]" value="$key">selected</eq>
                                                        >{$vo}
                                                        </option>
                                                    </volist>
                                                </select>
                                            </case>
                                            <case value="select">
                                                <select name="{$field.name}">
                                                    <volist name=":parse_field_attr($field['extra'])" id="vo">
                                                        <option value="{$key}" <eq name="data[$field['name']]" value="$key">selected</eq> >{$vo}
                                                        </option>
                                                    </volist>
                                                </select>
                                            </case>
                                            <case value="radio">
                                                <volist name=":parse_field_attr($field['extra'])" id="vo">
                                                        <input type="radio" value="{$key}" name="{$field.name}" <eq name="data[$field['name']]" value="$key">checked="checked"</eq>>{$vo}
                                                </volist>
                                            </case>
                                            <case value="checkbox">
                                                <volist name=":parse_field_attr($field['extra'])" id="vo">
                                                        <label><input type="checkbox" value="{$key}" name="{$field.name}[]" <if condition="check_document_position($data[$field['name']],$key)">checked="checked"</if>>{$vo}</label>
                                                </volist>
                                            </case>
                                            <case value="editor">
                                                <label class="textarea">
                                                    <textarea name="{$field.name}" data-toggle="kindeditor" data-minheight="200">{$data[$field['name']]}</textarea>
                                                </label>
                                            </case>
                                            <case value="file">
                                                <div class="controls">
                                                    <input type="file" id="upload_file_{$field.name}{$data.id}">
                                                    <input type="hidden" name="{$field.name}" value="{:think_encrypt(json_encode(get_table_field($data[$field['name']],'id','','File')))}"/>
                                                    <div class="upload-img-box">
                                                        <present name="data[$field['name']]">
                                                            <div class="upload-pre-file"><span class="upload_icon_all"></span>{$data[$field['name']]|get_table_field=###,'id','name','File'}</div>
                                                        </present>
                                                    </div>
                                                </div>
                                                <script type="text/javascript">
                                                    //上传文件
                                                    $.CurrentNavtab.find("#upload_file_{$field.name}{$data.id}").uploadify({
                                                        "height"          : 30,
                                                        "swf"             : "__BJUI/plugins/uploadify/scripts/uploadify.swf",
                                                        "fileObjName"     : "download",
                                                        "buttonText"      : "上传附件",
                                                        "uploader"        : "{:U('File/upload',array('session_id'=>session_id()))}",
                                                        "width"           : 120,
                                                        'removeTimeout'	  : 1,
                                                        "onUploadSuccess" : function(file, data){
                                                            var data = $.parseJSON(data);
                                                            if(data.status){
                                                                var name = "{$field.name}";
                                                                $.CurrentNavtab.find("input[name="+name+"]").val(data.data);
                                                                $.CurrentNavtab.find("input[name="+name+"]").parent().find('.upload-img-box').html(
                                                                        "<div class=\"upload-pre-file\">" +
                                                                        "<span class=\"upload_icon_all\"></span>" + data.info +
                                                                        "</div>"
                                                                );
                                                            } else {
                                                                $(this).alertmsg('error', data.info);
                                                            }
                                                        },
                                                        'onFallback' : function() {
                                                            alert('未检测到兼容版本的Flash.');
                                                        }
                                                    });
                                                </script>
                                            </case>
                                            <case value="picture">
                                                <div class="controls">
                                                    <input type="file" id="upload_picture_{$field.name}{$data.id}">
                                                    <input type="hidden" name="{$field.name}" value="{$data[$field['name']]}" id="cover_id_{$field.name}{$data.id}"/>
                                                    <div class="upload-img-box">
                                                        <notempty name="data[$field['name']]">
                                                            <div class="upload-pre-item">
                                                                <img src="{$data[$field['name']]|get_cover='path'}" style="max-width:500px;max-height:200px;"/>
                                                                <span onclick="delthispic{$field.name}{$data.id}(this)" dataid="{$v}," class="fa fa-trash" style="font-size:20px;"></span>
                                                            </div>
                                                        </notempty>
                                                    </div>
                                                </div>
                                                <script type="text/javascript">
                                                    //上传单图
                                                    $.CurrentNavtab.find("#upload_picture_{$field.name}{$data.id}").uploadify({
                                                        "height"          : 30,
                                                        "swf"             : "__BJUI/plugins/uploadify/scripts/uploadify.swf",
                                                        "fileObjName"     : "download",
                                                        "buttonText"      : "上传图片",
                                                        "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                                                        "width"           : 120,
                                                        'removeTimeout'	  : 1,
                                                        'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
                                                        "onUploadSuccess" : function(file, data){
                                                                var data = $.parseJSON(data);
                                                                var src = '';
                                                                console.log(data);
                                                                if(data.status){
                                                                    $.CurrentNavtab.find("#cover_id_{$field.name}{$data.id}").val(data.id);
                                                                    src = data.url || '__ROOT' + data.path
                                                                    $.CurrentNavtab.find("#cover_id_{$field.name}{$data.id}").parent().find('.upload-img-box').html(
                                                                            '<div class="upload-pre-item">' +
                                                                            '<img src="' + src + '" style="max-width:500px;max-height:200px;"/>' +
                                                                            '<span onclick="delthispic{$field.name}{$data.id}(this)" dataid="{$v}," class="fa fa-trash" style="font-size:20px;"></span>'+
                                                                            '</div>'
                                                                    );
                                                                } else {
                                                                    $(this).alertmsg('error', data.info);
                                                                }
                                                            },
                                                            'onFallback' : function() {
                                                                alert('未检测到兼容版本的Flash.');
                                                            }
                                                        });
                                                    /**
                                                     * 删除单图, 更新数据
                                                     */
                                                    function delthispic{$field.name}{$data.id}(obj) {
                                                        var dataids = '';   // 图片标识数据
                                                        $(obj).parent().remove();               // 移除父结点
                                                        // 更新数据
                                                        $.CurrentNavtab.find('#cover_id_{$field.name}{$data.id}').val('');
                                                    }
                                                </script>
                                            </case>
                                            <case value="uploadpics">
                                                <!-- 批量上传 -->
                                                <input type="file" id="upload_all_{$field.name}{$data.id}">
                                                <input type="hidden" name="{$field.name}" value="{$data[$field['name']]}" id="input_upload_all{$field.name}{$data.id}"/>
                                                <div id="uploadpics_piclist{$field.name}{$data.id}">
                                                    <ul class="highslide-gallery">
                                                        <notempty name="data[$field['name']]">
                                                            <?php
                                                         $pics=explode(',', $data[$field['name']]);
                                                         foreach($pics as $v){
                                                         if($v!=''){
                                                         ?>
                                                            <li>
                                                                <a href="__ROOT{$v|get_cover='path'}" target="_blank">
                                                                    <img src="__ROOT{$v|get_cover='path'}" style="max-width:500px;max-height:200px;"/></a>
                                                                <span onclick="delthispics{$field.name}{$data.id}(this)" dataid="{$v}," class="fa fa-trash" style="font-size:20px;"></span>
                                                            </li>
                                                            <?php
                                                         }
                                                         }
                                                         ?>
                                                        </notempty>
                                                    </ul>
                                                </div>
                                                <script type="text/javascript">
                                                    //上传多图
                                                    $.CurrentNavtab.find("#upload_all_{$field.name}{$data.id}").uploadify({
                                                        "height" : 30,
                                                        "swf" : "__BJUI/plugins/uploadify/scripts/uploadify.swf",
                                                        "fileObjName" : "download",
                                                        "buttonText" : "批量上传图片",
                                                        "uploader" : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                                                        "width" : 120,
                                                        'removeTimeout' : 1,
                                                        'fileTypeExts' : '*.jpg; *.png; *.gif;',
                                                        "onUploadSuccess" : function(file, data){
                                                                var data = $.parseJSON(data);
                                                                var src = '';
                                                                if(data.status){
                                                                    src = data.url || '__ROOT' + data.path;
                                                                    var value = '<li>' +
                                                                            '<a href="'+src+'" class="highslide" onClick="return hs.expand(this)">' +
                                                                            '<img src="' + src + '" style="max-width:1000px;max-height:200px;"/></a>' +
                                                                            '<span onclick="delthispics{$field.name}{$data.id}(this)" dataid="'+data.id+'," class="fa fa-trash" style="font-size:20px;"></span>' +
                                                                            '</li>';

                                                                    // 图片数据
                                                                    $.CurrentNavtab.find('#uploadpics_piclist{$field.name}{$data.id} ul').append(value);

                                                                    // 更新图片id数据
                                                                    var dataids = "";
                                                                    console.log($.CurrentNavtab.find('#uploadpics_piclist{$field.name}{$data.id} .fa-trash').length);
                                                                    $.CurrentNavtab.find('#uploadpics_piclist{$field.name}{$data.id} .fa-trash').each(function(){
                                                                        dataids += $(this).attr('dataid');
                                                                    })
                                                                    console.log(dataids);
                                                                    $.CurrentNavtab.find('#input_upload_all{$field.name}{$data.id}').val(dataids);
                                                                } else {
                                                                    $(this).alertmsg('error', data.info);
                                                                }
                                                            },
                                                            'onFallback' : function() {
                                                                alert('未检测到兼容版本的Flash.');
                                                            }
                                                        });
                                                    /**
                                                     * 删除多图, 更新数据
                                                     */
                                                    function delthispics{$field.name}{$data.id}(obj) {
                                                        var dataids = '';   // 图片标识数据
                                                        $(obj).parent().remove();               // 移除父结点
                                                        // 更新数据
                                                        $.CurrentNavtab.find('#uploadpics_piclist{$field.name}{$data.id} .fa-trash').each(function(){
                                                            dataids += $(this).attr('dataid');
                                                        })
                                                        $.CurrentNavtab.find('#input_upload_all{$field.name}{$data.id}').val(dataids);
                                                    }
                                                </script>
                                            </case>
                                            <case value="editor">
                                                <label class="textarea">
                                                    <div style="display: inline-block; vertical-align: middle;">
                                                        <textarea name="{$field.name}" class="j-content" style="width: 700px;" data-toggle="kindeditor" data-minheight="200">{$data[$field['name']]}</textarea>
                                                    </div>
                                                </label>
                                            </case>
                                            <default/>
                                            <input type="text" class="text input-large" name="{$field.name}" value="{$data[$field['name']]}"></switch>
                                    </div>
                                </div>
                            </if>
                                </div>
                        </volist>
                        </fieldset>
                    </div>
                    </volist>
                </div>
        </form>
    </div>
</block>